package com.weiiew.recipeservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.weiiew.common.entity.cal.TranslationRecipe;
import com.weiiew.common.entity.dto.RecipeBuilding;
import com.weiiew.common.entity.simple.DoublePair;
import com.weiiew.common.entity.vo.RecipeVO;
import com.weiiew.common.OnlyFeign.OnlyFeign;
import com.weiiew.recipeservice.mapper.RecipeBuildingMapper;
import com.weiiew.recipeservice.service.RecipeServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description
 * @Author 魏锴
 * @Date 2025/4/3
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/recipe/feign")
@OnlyFeign
public class RecipeFeignController {
    private final RecipeServiceImpl recipeService;
    private final RecipeBuildingMapper recipeBuildingMapper;
    @RequestMapping("/list/build")
    public List<RecipeVO> getRecipeByBuildingId(@RequestParam("build") int build){
        return recipeService.getRecipeByBuildingId(build);
    }
    @RequestMapping("/count/recipe/build")
    public Long countRecipeBuild(@RequestParam("build") int build){
        QueryWrapper<RecipeBuilding> wrapper = new QueryWrapper<RecipeBuilding>().eq("building_id", build);
        return recipeBuildingMapper.selectCount(wrapper);
    }
    @RequestMapping("/list/ingredient")
    public List<RecipeVO> getRecipeByIngredientId(@RequestParam("item") Integer item){
        return recipeService.getRecipeByIngredientId(item);
    }
    @RequestMapping("/list/product")
    public List<RecipeVO> getRecipeByProductId(@RequestParam("item") Integer item){
        return recipeService.getRecipeByProductId(item);
    }

    @PostMapping("/list/item")
    List<DoublePair> getFactoryRecipeById(
            @RequestParam("item") Integer item,
            @RequestParam("recipe") Integer recipe){
        return recipeService.getFactoryRecipeById(item, recipe);
    }

    @PostMapping("/list/translation")
    TranslationRecipe getTranslationRecipe(
            @RequestParam("item") Integer item,
            @RequestParam("recipe") Integer recipe){
        return recipeService.getTranslationRecipe(item, recipe);
    }
}
